package com.yxq.mdt.app.modules.personal.model;

import com.yxq.mdt.app.base.ibase.IBaseModel;
import com.yxq.mdt.app.modules.personal.bean.MyPersonalBean;
import com.yxq.mdt.app.modules.personal.bean.MyRelationBean;
import com.yxq.mdt.app.net.ApiModel;
import com.yxq.mdt.app.net.BaseObserver;
import com.yxq.mdt.app.net.RetrofitFactory;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

/**
 * @author L
 * @time 2019-11-20
 * @describe $
 */
public class RelationModel implements IBaseModel {

    //粉丝/关注/喜欢 列表
    public void selectMyRelationList(String userId, int type, int tagType, String searchName, int pageNum, int pageSize, ApiModel.CommonCallback<MyRelationBean> callback) {
        RetrofitFactory.getJavaRetrofit().create(RelationAPI.class)
                .selectMyRelationList(userId, type, tagType, searchName, pageNum, pageSize)
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<MyRelationBean>() {
                    @Override
                    public void onFailure(Throwable e, boolean isNetWorkError) {
                        callback.onError(e.getMessage());
                    }

                    @Override
                    public void onSuccess(MyRelationBean respBase) {
                        callback.onSuccess(respBase);
                    }
                });
    }

    //关注/取消关注 喜欢/不喜欢
    public void saveUsersRelation(String userId, int type, int enabled, ApiModel.CommonCallback<MyRelationBean> callback) {
        RetrofitFactory.getJavaRetrofit().create(RelationAPI.class)
                .saveUsersRelation(userId, type, enabled)
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<MyRelationBean>() {
                    @Override
                    public void onFailure(Throwable e, boolean isNetWorkError) {
                        callback.onError(e.getMessage());
                    }

                    @Override
                    public void onSuccess(MyRelationBean respBase) {
                        callback.onSuccess(respBase);
                    }
                });
    }

    @Override
    public void onDestroy() {

    }
}
